﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ArraylistTest
{
    class Program
    {
        static void Main(string[] args)
        {
            //建立arraylist对象
            ArrayList students = new ArrayList() { "kk", "ll", "pp" };
            students.Add("make");
            students.Add("lili");
            students.Add("张三");
            students.Add("李四");
            students.Sort(); //利用Sort()进行排序
            foreach (var v in students)//排序后遍历数组
            {
                Console.WriteLine(v);
            }
            int index = students.IndexOf("ll");
            if (index != -1)
            {
                Console.WriteLine("该集合中存在ll元素");
            }
            else
            {
                Console.WriteLine("该集合中不存在ll元素");
            }
            Console.WriteLine("下标为奇数的元素为：");
          
            ArrayList stu = new ArrayList();
            for (int i = 0; i < students.Count; i = i + 2)
            {
                stu.Add(students[i]);
            }
            foreach (var v in stu)
            {
                Console.WriteLine(v);
            }
            Console.ReadLine();
           
            ArrayList insertstu = new ArrayList() { "小小", "sir", "楠楠" };
            students.InsertRange(1, insertstu);
            foreach (var v in students)
            {
                Console.WriteLine(v);
            }
            Console.ReadLine();
           
            MyCompare myCompare = new MyCompare();
            students.Sort(myCompare);
            foreach (var v in students)
            {
                Console.WriteLine(v);
            }
        }
    }
}
